#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2021/12/21 14:32
# @Author  : tianqunhui
# @contact : tqunhui@qq.com
# @File    : tianqunhui_03.py
# @Software: PyCharm



def singleton(cls):
    # 例装饰器
    instances = {}
    def _singleton():
        if cls not in instances:
            instances[cls] = cls()
        return instances[cls]
    return _singleton


@singleton
class Test(object):
    pass


obj1 = Test()
obj2 = Test()

assert obj1 is obj2, "不是单例"

print(id(obj1))
print(id(obj2))